package com.kuang.controller;

import com.github.pagehelper.PageInfo;
import com.kuang.entity.Achievement;
import com.kuang.entity.AchievementType;
import com.kuang.entity.Params;
import com.kuang.entity.SysUser;
import com.kuang.service.*;
import com.kuang.util.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private UserService userService;
    @Autowired
    private AchievementTypeService achievementTypeService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private MajorService majorService;
    @Autowired
    private AchievementService  achievementService;



    /***
     * 注册账号申请管理
     * **/
    @PutMapping("/accountManagement")
    public ResultModel accountManagement(@RequestBody SysUser sysUser){
        userService.accountManagement(sysUser);
        return ResultModel.success();
    }
    /**
     * 根据id删除用户
     **/
    @DeleteMapping("/delete/{id}")
    public ResultModel deleteByPrimaryKey(@PathVariable Integer id) {
        userService.deleteByPrimaryKey(id);
        return ResultModel.success();
    }

    /**
     * 批量删除
     * **/
    @PostMapping("/delBarch")
    public ResultModel deleteByIds(@RequestBody List<SysUser> list){
        for (SysUser sysUser : list){
            userService.deleteByPrimaryKey(sysUser.getId());
        }
        return ResultModel.success();
    }

    /**
     * 学生账号分页查询
     */
    @GetMapping("/searchStudent")
    public ResultModel findBySearchStudent(Params params) {
        PageInfo info = userService.findBySearchStudent(params);
        return ResultModel.success(info);
    }
    /**
     * 管理员：教师账号分页查询
     */
    @GetMapping("/searchTeacher")
    public ResultModel findBySearchTeacher(Params params) {
        PageInfo info = userService.findBySearchTeacher(params);
        return ResultModel.success(info);
    }
    /**
     * 管理员：学习成果认定分页查询
     */
    @GetMapping("/searchAffirm")
    public ResultModel findBySearchAffirm(Params params) {
        PageInfo info = achievementService.findBySearchAffirm(params);
        return ResultModel.success(info);
    }
    /**
     * 学习成果转换分页查询
     */
    @GetMapping("/searchTransitio")
    public ResultModel findBySearchTransition(Params params) {
        PageInfo info = achievementService.findBySearchTransition(params);
        return ResultModel.success(info);
    }
    /**
     *查询学院下拉框信息
     * **/
    @GetMapping("/findAll")
    public ResultModel findAll() {
        List list = departmentService.findAll();
        return ResultModel.success(list);
    }

    /**
     *查询专业下拉框信息
     * **/
    @GetMapping("/findAoo")
    public ResultModel findAoo() {
        List list = majorService.findAoo();
        return ResultModel.success(list);
    }
    /**
     * 类别分页查询
     */
    @GetMapping("/typeAll")
    public ResultModel findTypeAll(Params params) {
        PageInfo info = achievementTypeService.findTypeAll(params);
        return ResultModel.success(info);
    }

    /**
     *添加类别信息
     * **/
    @PostMapping("/typeAdd")
    public ResultModel findTypeAdd(@RequestBody AchievementType achievement_type) {
        achievementTypeService.findTypeAdd(achievement_type);
        return ResultModel.success();
    }

    /**
     *删除类别信息
     * **/
    @DeleteMapping("/{id}")
    public ResultModel deleteById(@PathVariable Integer id){
        achievementTypeService.deleteById(id);
        return ResultModel.success();
    }

    /**
     *修改类别信息
     * **/
    @PutMapping("/updateById")
    public ResultModel updateById(@RequestBody AchievementType achievement_type){
        achievementTypeService.updateById(achievement_type);
        return ResultModel.success();
    }
    /**
     * 认定审核通过
     * **/
    @PutMapping("/affirmAchievementPass")
    public ResultModel SuccessfullyApprovedAchievement(@RequestBody Achievement achievement){
        achievementService.SuccessfullyApprovedAchievement(achievement);
        return ResultModel.success();
    }
    /**
     * 认定审核不通过
     * **/
    @PutMapping("/affirmAchievementFail")
    public ResultModel failApprovedAchievement( @RequestBody Achievement achievement){
        achievementService.failApprovedAchievement(achievement);
        return ResultModel.success();
    }
    /**
     * 转换审核通过
     * **/
    @PutMapping("/PassTransformationOfLearningOutcomes")
    public ResultModel PassTransformationOfLearningOutcomes(@RequestBody Achievement achievement){
        achievementService.PassTransformationOfLearningOutcomes(achievement);

        return ResultModel.success();
    }
    /**
     * 转换审核不通过
     * **/
    @PutMapping("/FailTransformationOfLearningOutcomes")
    public ResultModel FailTransformationOfLearningOutcomes( @RequestBody Achievement achievement){
        achievementService.FailTransformationOfLearningOutcomes(achievement);
        return ResultModel.success();
    }
}
